<template>
	<view class="page">
		<view class="search-box s-flex-r-s-c">
			<u-search placeholder="请输入名称" v-model="keyword" search-icon-color="rgba(174,174,174,1)"
				:show-action="false" @search="reload"></u-search>
			<view class="s-flex-r-s-c" @click="go('shopMore')">
				<text class="search-text">更多</text>
				<u-icon name="more-dot-fill" color="#2979ff" size="28"></u-icon>
			</view>
		</view>
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" top="100" bottom="0" @down="downCallback" @up="upCallback">
			<view class="list s-flex-r-s-s">
				<view class="listCol flex1">
					<image class="good" @click="go('shopMore')" v-if="list.length" src="/static/recommondedItems.png" mode="widthFix"></image>
					<view class="item item-left" v-for="(item,index) in leftList" :key="index" @click='goDetails(item.id)'>
						<image class="img" :src="item.mainCover" mode="widthFix"></image>
						<view class="name">{{item.goodsName}}</view>
						<view class="price">¥ {{item.price}}</view>
					</view>
				</view>
				<view class="listCol flex1">
					<view class="item" v-for="(item,index) in rightList" :key="index" @click='goDetails(item.id)'>
						<image class="img" :src="item.mainCover" mode="widthFix"></image>
						<view class="name">{{item.goodsName}}</view>
						<view class="price">¥ {{item.price}}</view>
					</view>
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>
<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js"
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				keyword: "",
				leftList: [],
				rightList: [],
				list: [],
			}
		},
		methods: {
			reload() {
				this.list = []
				console.log('this.list: ', this.list)
				this.mescroll.resetUpScroll()
			},
			upCallback(page) {
				this.httpClient.post('agents/app/shopping/goodsIndexList', {
					pageNum: page.num,
					pageSize: page.size,
					goodsName: this.keyword
				}).then(res => {
					this.mescroll.endByPage(res.rows.length, res.total);
					//this.mescroll.endSuccess(res.data.length);
					if (page.num == 1) this.list = [];
					this.list = this.list.concat(res.rows);
					this.leftList =  [];
					this.rightList =  [];
					this.list.map((item,index)=>{
						if(index%2==0){
							this.rightList.push(item)
						}else{
							this.leftList.push(item)
						}
					})
				}).catch(() => {
					this.mescroll.endErr();
				})
			},
			goDetails(id) {
				uni.navigateTo({
					url: 'shopDetails?id=' + id
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.page{
		background: #f5f5f5;
	}
	.list-wrap{
		width: 100%;
	}
	.search-box {
		height: 100rpx;
		background: #fff;
		padding-left: 20rpx;
		padding-right: 15rpx;

		.search-text {
			margin-left: 20rpx;
			margin-right: 10rpx;
			color: $uni-color-primary;
		}
	}

	.list {
		padding: 10rpx;
		.listCol{
			width: 354rpx;
			overflow: hidden;
		}
		.good {
			width: 354rpx;
			height: 172rpx;
			margin-bottom: 24rpx;
		}

		.item {
			background: #fff;
			border-radius: 10rpx;
			padding:16rpx;
			margin-bottom: 24rpx;

			.img {
				width: 324rpx;
			}
			.name{
				width: 324rpx;
				word-break:break-all;
				word-wrap:break-word;
			}
			.price {
				margin-top: 6rpx;
				color: #f14444;
				font-weight: bold;
			}
		}
		.item-left{
			margin-right: 18rpx;
		}
	}
</style>